<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Git操作总结 | Kc的博客</title>
    <meta name="generator" content="VuePress 1.5.4">
    <link rel="icon" href="/img/prompt.png">
    <link rel="stylesheet" href="/css/style.css">
    <script src="/js/main.js"></script>
    <meta name="description" content="谁来督促我写blog">
    <link rel="preload" href="/assets/css/0.styles.ccac5a78.css" as="style"><link rel="preload" href="/assets/js/app.d62b2ae9.js" as="script"><link rel="preload" href="/assets/js/2.96f3cffc.js" as="script"><link rel="preload" href="/assets/js/10.d376fefb.js" as="script"><link rel="prefetch" href="/assets/js/11.6f69af3f.js"><link rel="prefetch" href="/assets/js/12.e521ba13.js"><link rel="prefetch" href="/assets/js/13.0169d26e.js"><link rel="prefetch" href="/assets/js/14.06083ba6.js"><link rel="prefetch" href="/assets/js/15.d36dd989.js"><link rel="prefetch" href="/assets/js/3.c15b449a.js"><link rel="prefetch" href="/assets/js/4.1cfc2f80.js"><link rel="prefetch" href="/assets/js/5.46b265b1.js"><link rel="prefetch" href="/assets/js/6.518c9c90.js"><link rel="prefetch" href="/assets/js/7.91014483.js"><link rel="prefetch" href="/assets/js/8.d25ee443.js"><link rel="prefetch" href="/assets/js/9.d986ac6b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.ccac5a78.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">Kc的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/guide/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  HTML
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="CSS" class="dropdown-title"><span class="title">CSS</span> <span class="arrow down"></span></button> <button type="button" aria-label="CSS" class="mobile-dropdown-title"><span class="title">CSS</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/csscontent/othcss/" class="nav-link">
  less|scss
</a></li><li class="dropdown-item"><!----> <a href="/csscontent/transition/" class="nav-link">
  动画
</a></li></ul></div></div><div class="nav-item"><a href="/jscontent/" class="nav-link">
  JS|Typescript
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工具" class="dropdown-title"><span class="title">工具</span> <span class="arrow down"></span></button> <button type="button" aria-label="工具" class="mobile-dropdown-title"><span class="title">工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://tool.oschina.net/encrypt?type=3" target="_blank" rel="noopener noreferrer" class="nav-link external">
  解码
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://tool.lu/timestamp/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  在线时间戳转换
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://designer.mocky.io/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  在线mock
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="收藏网页|博客" class="dropdown-title"><span class="title">收藏网页|博客</span> <span class="arrow down"></span></button> <button type="button" aria-label="收藏网页|博客" class="mobile-dropdown-title"><span class="title">收藏网页|博客</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitlab.redrock.team/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  gitlab
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/guide/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  HTML
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="CSS" class="dropdown-title"><span class="title">CSS</span> <span class="arrow down"></span></button> <button type="button" aria-label="CSS" class="mobile-dropdown-title"><span class="title">CSS</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/csscontent/othcss/" class="nav-link">
  less|scss
</a></li><li class="dropdown-item"><!----> <a href="/csscontent/transition/" class="nav-link">
  动画
</a></li></ul></div></div><div class="nav-item"><a href="/jscontent/" class="nav-link">
  JS|Typescript
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工具" class="dropdown-title"><span class="title">工具</span> <span class="arrow down"></span></button> <button type="button" aria-label="工具" class="mobile-dropdown-title"><span class="title">工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://tool.oschina.net/encrypt?type=3" target="_blank" rel="noopener noreferrer" class="nav-link external">
  解码
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://tool.lu/timestamp/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  在线时间戳转换
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://designer.mocky.io/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  在线mock
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="收藏网页|博客" class="dropdown-title"><span class="title">收藏网页|博客</span> <span class="arrow down"></span></button> <button type="button" aria-label="收藏网页|博客" class="mobile-dropdown-title"><span class="title">收藏网页|博客</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitlab.redrock.team/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  gitlab
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>基础语法</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/guide/notes/one.html" class="sidebar-link">一级标题</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>注意事项</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="git操作总结"><a href="#git操作总结" class="header-anchor">#</a> Git操作总结</h1> <h3 id="_1-基础操作篇"><a href="#_1-基础操作篇" class="header-anchor">#</a> 1.基础操作篇</h3> <ul><li><p><strong>git init</strong> 建立本地仓库</p></li> <li><p><strong>git remote add origin xxxxxxxxxxx</strong> 关联远程仓库</p> <ul><li><p><strong>origin</strong> 为远程仓库名字可以有多个远程仓库</p></li> <li><div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> remote -v 查看本地远程库
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li> <li><table><thead><tr><th>bash</th> <th>vscode</th></tr></thead> <tbody><tr><td>git remote add origin https://github.com/kczssd/Git-.git</td> <td><img src="/img/remote.png" alt="remote"></td></tr></tbody></table></li></ul></li> <li><p><strong>git clone xxxxxxxxxx</strong> 克隆远程仓库</p></li> <li><p><strong>git add</strong> 把工作区文件提交到暂存区</p> <ul><li><table><thead><tr><th>bash</th> <th>vscode</th></tr></thead> <tbody><tr><td>git add --all(当前项目里) | git add .(当前项目) | git add xxx(指定文件)</td> <td><img src="/img/add.png" alt="add"></td></tr></tbody></table></li> <li><div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> status 查看文件改变状态
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li></ul></li> <li><p><strong>git commit -m&quot;写对commit的描述&quot;</strong> 提交到本地仓库</p> <ul><li><table><thead><tr><th>bash</th> <th>vscode</th></tr></thead> <tbody><tr><td>git commit -m&quot;add:a b c&quot;</td> <td><img src="/img/coommit.png" alt="coommit"></td></tr></tbody></table></li> <li></li></ul></li> <li><p><strong>git push</strong> 推送到远程仓库</p> <ul><li><p>第一次使用git push -u origin master</p></li> <li><table><thead><tr><th>bash</th> <th>vscode</th></tr></thead> <tbody><tr><td>git push -u origin master</td> <td><img src="/img/push1.png" alt="push1"></td></tr></tbody></table> <ul><li>master 可以切换push的远程仓库</li></ul></li> <li><p><strong>git branch -a</strong> 查看本地和远程分支</p></li></ul></li></ul> <h3 id="_2-代码撤销修改"><a href="#_2-代码撤销修改" class="header-anchor">#</a> 2.代码撤销修改</h3> <blockquote><p>未暂存时</p></blockquote> <ul><li><p><strong>git diff</strong> 列出所有的修改</p> <ul><li><table><thead><tr><th>git diff |git diff 具体文件</th> <th><img src="/img/change.png" alt="change"></th></tr></thead> <tbody><tr><td>-表示移除代码+表示增加代码</td> <td><img src="/img/change_2.png" alt="change_2"></td></tr></tbody></table></li></ul></li> <li><p>git checkout 撤销修改 | git clean -f/-df 撤销新增文件/文件夹</p> <ul><li><table><thead><tr><th>git checkout | git checkout 具体文件</th> <th><img src="/img/checkout.png" alt="checkout"></th></tr></thead> <tbody><tr><td>git clean -f | fit clean -df</td> <td><img src="/img/checkout.png" alt="checkout"></td></tr></tbody></table></li></ul></li></ul> <blockquote><p>未提交</p></blockquote> <ul><li><strong>git diff --cached</strong> 显示暂存区和本地仓库
<ul><li>git diff --cached | <img src="/img/diff.png" alt="diff"></li></ul></li> <li>git reset 暂存区到工作区<img src="/img/reset.png" alt="reset"> <ul><li>git reset --hard 回到工作区未修改状态</li></ul></li></ul> <blockquote><p>未推送</p></blockquote> <ul><li><strong>git diff master origin/master</strong> 比较本地仓库和远程仓库的差异</li> <li><strong>git diff branch1 branch2</strong> 比较两个分支的差异</li> <li>git reset --hard origin/master 回退到与本地远程仓库一致</li> <li><em><strong>git reset --hard HEAD^</strong></em> 回退到本地仓库上一个版本(<strong>版本回退</strong>)
<ul><li>git reset --hard 哈希值回退到指定版本</li></ul></li></ul> <h3 id="_3-分支相关"><a href="#_3-分支相关" class="header-anchor">#</a> 3.分支相关</h3> <ul><li><strong>git branch</strong> 查看本地分支
<ul><li>git branch -a 查看本地远程分支</li></ul></li> <li><strong>git branch 分支名</strong> 创建分支</li> <li><strong>git checkout 分支名</strong> 切换分支
<ul><li>git checkout -b 分支名 创建并切换分支</li></ul></li> <li>git merge 分支名 把分支合并到本地分支</li></ul> <h3 id="版本相关"><a href="#版本相关" class="header-anchor">#</a> 版本相关</h3> <ul><li><strong>git log</strong> 查看commit版本
<ul><li>git log --graph --decorate --abbrev-commit --all 图形化展示</li></ul></li> <li>git reflog 查看最近执行操作及所处的版本</li></ul></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.d62b2ae9.js" defer></script><script src="/assets/js/2.96f3cffc.js" defer></script><script src="/assets/js/10.d376fefb.js" defer></script>
  </body>
</html>
